package com.huangyi.fileservice.controller;


import com.huangyi.commoncore.utils.BeanCopyUtil;
import com.huangyi.commondomain.domain.R;
import com.huangyi.fileservice.domain.DTO.FileDTO;
import com.huangyi.fileservice.domain.DTO.SignDTO;
import com.huangyi.fileservice.domain.VO.FileVO;
import com.huangyi.fileservice.domain.VO.SignVO;
import com.huangyi.fileservice.service.IFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
 * 文件管理控制器
 */
@Slf4j
@RestController
public class FileController {

    @Autowired
    private IFileService fileService;

    /**
     * 上传文件
     * @param file 上传的文件
     * @return 返回结果
     */

    @PostMapping("/upload")
    public R<FileVO> uploadFile(MultipartFile file) {
        FileDTO fileDTO = fileService.uploadFile(file);
        FileVO fileVO = new FileVO();
        BeanCopyUtil.copyProperties(fileDTO, fileVO);
        return R.ok(fileVO);
    }

    /**
     * 获取签名
     * @return 签名
     */
    @PostMapping("/getSign")
    public R<SignVO> getSign() {
        SignDTO signDTO = fileService.getSign();
        SignVO signVO = new SignVO();
        BeanCopyUtil.copyProperties(signDTO, signVO);
        return R.ok(signVO);
    }
}
